
function WSS(url) {
	this.socket = new WebSocket(url)
	
	this.socket.onopen = function() {
		console.log("WS onopen");
	}
	this.socket.onmessage = function(evt) {
		console.log("WS onmessage:" + evt.data)
		
		var role = evt.data.split(":")[0];
		var win = window.roles[role];
		var data = evt.data;
		if (win) {
			data = data.substring(evt.data.search(":") + 1)
		} else {
			win = window.win;
		}
		if (win) {
			
			if (window.msgHandler) {
				window.msgHandler(data)
			} else {
				win.addReply(data);
			}
			// do something else
		}
	}
	this.socket.onclose = function(evt) {
		console.log("WS onclose")
	}
	this.socket.onerror = function(evt) {
		console.log("WS onerror")
	}
	
	WSS.prototype.emit = function(data){
		this.socket.send(data)
	}
	WSS.prototype.close = function() {
		this.socket.send("close")
	}
}